package com.A21.GuoSai.demo.workflow_adjust.controller;

import com.A21.GuoSai.demo.atom_adjust.service.AtomPojoService;
import com.A21.GuoSai.demo.service_entity.entity.atom.AtomServicePojo;
import com.A21.GuoSai.demo.service_entity.entity.workflow.DynamicVarValuePojo;
import com.A21.GuoSai.demo.workflow_adjust.service.WorkFlowPojoService;
import com.A21.GuoSai.demo.workflow_adjust.service.ZeebeDeployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/workflow")
public class WorkFlowController {

    @Autowired
    private ZeebeDeployService zeebeDeployService;

    @Autowired
    private WorkFlowPojoService workFlowPojoService;


    @GetMapping("/{flowId}")
//    http://localhost:10001/workflow/Process_1cwrqoj
//    执行工作流的接口，不过这个以Qrj的接口为准，我这里为了测试方便，使用的是异步执行
    public void executeWorkFlow(@PathVariable("flowId") String flowId){
        Map<String,Object>map=new HashMap<>();
        zeebeDeployService.executeWorkFlow(flowId,map);
    }

    @GetMapping("/getAtomAttributes/{flowId}")
//    《服务编排界面》
//    这个接口会返回flowId所对应的工作流中包含的所有原子服务信息，以及
//    这些原子服务对应的参数名、参数描述、参数值等等
//    http://localhost:10001/workflow/getAtomAttributes/my3-1
    public ResponseEntity<List<AtomServicePojo>> getAtoms(@PathVariable("flowId") String flowId){
        return ResponseEntity.ok(workFlowPojoService.getWorkerFlowStaVarByFlowId(flowId));
    }


    @GetMapping("/debug/dynVars/{flowId}")
//    《调试界面》
//    这个接口会返回flowId所对应的工作流的所有动态变量信息
//    包括动态变量的变量名、变量类型、变量描述
    public List<DynamicVarValuePojo> getDynVarsForDebugWorkFlow(@PathVariable("flowId") String flowId){
        return workFlowPojoService.getWorkerFlowDynVarValueByFlowId(flowId);
    }
}
